
** note there is an issues with players 61, 63, 64, and 65 ... doublecounting because it was a four person session ... player 62 dropped out after the baseline**


********************************
*** rename commands reshape ***
********************************
				gen player_stacked1 = row if row == "A"
				gen player_stacked2 = row if row == "B"
				gen player_stacked3 = row if row == "C"
				gen player_stacked4 = row if row == "D"
				gen player_stacked5 = row if row == "E"

				
				gen shockeda = 0
				replace shockeda = 1 if shocked == 1 & row =="A"
				gen shockedb=0
				replace shockedb = 1 if shocked == 1 & row =="B"
				gen shockedc = 0
				replace shockedc = 1 if shocked == 1 & row =="C"
				gen shockedd = 0
				replace shockedd = 1 if shocked == 1 & row =="D"
				gen shockede = 0

				replace shockede = 1 if shocked == 1 & row =="E"

				replace shockede = . if shocked == .
				replace shockedd = . if shocked == .
				replace shockedc = . if shocked == .
				replace shockedb = . if shocked == .
				replace shockeda = . if shocked == .

		

				rename shockeda shockedstacked1 
				rename shockedb shockedstacked2 
				rename shockedc shockedstacked3 
				rename shockedd shockedstacked4 
				rename shockede shockedstacked5 

		
		rename sharewitha sharewith1 
		rename sharewithb sharewith2 
		rename sharewithc sharewith3 
		rename sharewithd sharewith4 
		rename sharewithe sharewith5 
		
		 
		rename punisha punish1 
		rename punishb punish2 
		rename punishc punish3 
		rename punishd punish4 
		rename punishe punish5 
		 
		rename sharewitha_adj sharewith_adj1 
		rename sharewithb_adj sharewith_adj2 
		rename sharewithc_adj sharewith_adj3 
		rename sharewithd_adj sharewith_adj4 
		rename sharewithe_adj sharewith_adj5 
		
		rename punisha_adj punish_adj1 
		rename punishb_adj punish_adj2 
		rename punishc_adj punish_adj3 
		rename punishd_adj punish_adj4 
		rename punishe_adj punish_adj5 
		 
		rename dictatorgivetoa dictatorgiveto1  
		rename dictatorgivetob dictatorgiveto2 
		rename dictatorgivetoc dictatorgiveto3 
		rename dictatorgivetod dictatorgiveto4 
		rename dictatorgivetoe dictatorgiveto5 
		 
		rename investa invest1 
		rename investb invest2 
		rename investc invest3 
		rename investd invest4 
		rename investe invest5 
		 
		rename gap_a gap_1 
		rename gap_b gap_2 
		rename gap_c gap_3 
		rename gap_d gap_4 
		rename gap_e gap_5 
		
		rename punish mypunish
		rename invest myinvest

		/*
		rename sharewitha_adj sharing_with
		rename punisha_adj punish_to
		rename gap_a investment_gap
		rename row player_letter
		rename investa invest_other
		*/


	 	sort treatment sessionid group round row


		reshape long sharewith sharewith_adj punish punish_adj dictatorgiveto invest gap_ shockedstacked player_stacked, i(sub_id round) j(player_letter)


		*** check this		
		
		rename gap_ investment_gap
		rename invest invest_others
		rename punish punish_others
		rename sharewith share_others
		rename sharewith_adj share_othersadj
		** only use share_othersadj - accounts for can't share if shocked and can't share with self
		


		keep treatment_a rd_player player_stacked rd_row player player_letter endowment punish_others invest_others private myinvest mypunish grptotal grpreturns pgearnings shockedstacked amtreceived punishgiven punishreceived totalearnings roundup roundcounts showup finalearnings dictatortotalreceived blue sessionid round confused four_person sub_id stage stage1 stage2 group earnings exp_id baseline treatment treatment_cont shock person4 noplayer  sharing group_sharing sharing_pctofgroup group_sharing_avg group_received round_received mean_round_received mean_received_overall pos_gap neg_gap share_othersadj punish_adj dictatorgiveto investment_gap gap_ap gap_an gap_ae

		* treatment_const
		
		
	** fix the shockedstacked variable **
		by exp_id round player_letter, sort: egen shock_stack = total(shockedstacked)
		drop shockedstacked
		label var shock_stack "player letter receiving shock"
		
		
		label var player_letter "letter of the player being given to 1=A, 2=B, etc."

		gen player_deciding = .
		replace player_deciding = 1 if player_stacked == "A"
		replace player_deciding = 2 if player_stacked == "B"
		replace player_deciding = 3 if player_stacked == "C"
		replace player_deciding = 4 if player_stacked == "D"
		replace player_deciding = 5 if player_stacked == "E"
		
		by exp_id round sub_id, sort: egen player_deciding2 = total(player_deciding)
		drop player_deciding
		rename player_deciding2 player_deciding
		label var player_deciding "numeric equivalent of player making the decision 1=A, 2=B, etc."


		drop player rd_player noplayer		
		
		sort exp_id round sub_id player_letter
		xtset sub_id
		

